/*
 * Created on Jan 16, 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.scohen.juploadr.uploadapi.zooomr.authentication;

import org.scohen.juploadr.uploadapi.zooomr.DefaultZooomrHandler;
import org.xml.sax.SAXException;

/**
 * @author steve
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class ZooomrAuthHandler extends DefaultZooomrHandler {
    private ZooomrAuth auth;

    /*
     * <?xml version="1.0" encoding="utf-8" ?> <user> <username>Bees </username>
     * <status> <pro>1 </pro> </status> <transfer> <limit>107374182400 </limit>
     * <used>8925364 </used> </transfer> </user>
     * 
     * <?xml version="1.0" encoding="utf-8" ?> <rsp stat="fail"> <err code="1"
     * msg="Invalid login details" />
     */
    public ZooomrAuthHandler(Object auth) {
        super(auth);
        this.auth = (ZooomrAuth) auth;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.xml.sax.ContentHandler#characters(char[], int, int)
     */
    public void characters(char[] chars, int start, int end)
            throws SAXException {
        String cdata = new String(chars, start, end).trim();

        if (cdata.length() > 0) {
            if ("username".equals(lastTag)) {
                auth.setUsername(cdata);
            } else if ("pro".equals(lastTag)) {
                auth.setPro("1".equals(cdata.trim()));
            } else if ("limit".equals(lastTag)) {
                auth.setMonthlyUploadLimit(Long.parseLong(cdata));
            } else if ("used".equals(lastTag)) {
                auth.setCurrentUploadUsed(Long.parseLong(cdata));
            }
        }
    }
}
